# 事件管理页面测试
import unittest
from ddt import ddt
from Lib.common.common_function import *
from Lib.base.page_object.login_page import LonginPage
from Lib.base.page_object.case_manager.case_manager import CaseManager
from selenium.webdriver.common.by import By
from Lib.base.keywords import KeyWords
from Lib.common.ui_log import error_log, normal_log

import allure
import os
from Lib.common.assert_class import AssertClass
import pytest


@pytest.fixture(scope='class', autouse=True)
@pytest.mark.usefixtures('login')
def set_cls(login):
    TestCaseManager.caseManager = CaseManager(login)
    TestCaseManager.assert_class = AssertClass(login)


@allure.feature('事件管理页面测试')
class TestCaseManager:

    @allure.title('根据事件来源筛选')
    def test_1_look_by_case_from(self):
        self.caseManager.look_by_case_from()
        assert_args = (By.XPATH, '//tbody/tr/td[10]//span')
        self.assert_class.make_assert_by_elements_text(args=assert_args, assert_data='AIOT感知', context='根据事件来源进行筛选')

    @allure.title('根据事件类型筛选事件')
    def test_2_look_by_case_type(self):
        self.caseManager.look_by_case_type()
        assert_args = (By.XPATH, '//tbody/tr[1]/td[2]//span')
        self.assert_class.make_assert_by_text(args=assert_args, assert_data='规划', context='根据事件类型进行筛选')

    @allure.title('根据事件阶段筛选事件')
    def test_3_look_by_case_stage(self):
        self.caseManager.look_by_case_stage()
        assert_args = (By.XPATH, '//tbody/tr[1]/td[8]//span')
        self.assert_class.make_assert_by_text(args=assert_args, assert_data='受理', context='根据事件类型进行筛选')

    @allure.title('根据事件状态筛选事件')
    def test_4_look_by_case_status(self):
        self.caseManager.look_by_case_status()
        # 设置断言
        assert_args = (By.XPATH, '//tbody/tr[1]/td[9]//span')
        self.assert_class.make_assert_by_text(args=assert_args, assert_data='已上报', context='事件状态')

    @allure.title('根据时间和关键字进行筛选事件')
    def test_5_look_by_case_time_and_keyword(self):
        self.caseManager.look_by_case_time_and_keyword()
        # 设置断言
        assert_args = (By.XPATH, '//tbody/tr[1]/td[5]//span')
        self.assert_class.make_assert_by_text(args=assert_args, assert_data='上海', context='事发地点')

    @allure.title('排序操作')
    def test_6_look_by_case_urgency_sort(self):
        self.caseManager.look_by_case_urgency_sort()
        # 设置断言
        assert_args1 = (By.XPATH, '//table[@class="rz-table__body"]//tr[1]/td[7]/div/div')
        assert_args2 = (By.XPATH, '//table[@class="rz-table__body"]//tr[2]/td[7]/div/div')
        self.assert_class.make_assert_by_compare_time(args1=assert_args1, args2=assert_args2, context="更新时间")

    @allure.title('查看事件详情')
    def test_7_look_case_detail(self):
        self.caseManager.look_case_detail()
        # 设置断言
        assert_args = (By.XPATH, '//span[text()="事件详情"]')
        self.assert_class.make_assert_by_text(args=assert_args, assert_data='事件详情', context='事件详情')

    @allure.title('查看已处理、 已过期、 未配置流程事件')
    def test_8_look_case_already(self):
        '''
        查看已处理、 已过期、 未配置流程事件
        :return:
        '''
        self.caseManager.look_case_already()
        # 设置断言
        assert_args = (By.XPATH, '//span[text()="未配置流程的事件"]')
        self.assert_class.make_assert_by_text(args=assert_args, assert_data="未配置流程的事件")


if __name__ == '__main__':
    pytest.main(
        ['-v', '-s',
         './case_manager_test.py::TestCaseManager'])
    # pytest.main(['-v', './business_test.py', '--alluredir', '../result', '--clean-alluredir'])
    # os.system(r'copy ..\config\environment.properties ..\result\environment.properties')
    # os.system('allure generate  ../result -o ../report/ --clean')
